<template>
  <div class="homeBox">
    <div class="left">
      <div class="leftNav">
        <el-menu
          :collapse="isCollapse"
          :default-active="activeIndex"
          class="elMenu"
          background-color="#333"
          text-color="#B0B0B2"
          active-text-color="#fff"
          :unique-opened="true"
          router
          ref="elMenu"
          @select="menuSelect"
        >
          <!-- 递归动态菜单 -->
          <myitem :data="menuArr"></myitem>
        </el-menu>
      </div>
    </div>
    <div class="right">
      <div class="rightTop">
        <i
          class="el-icon-s-fold"
          v-show="isCollapse == false"
          @click="isCollapse = true"
        ></i>
        <i
          class="el-icon-s-unfold"
          v-show="isCollapse == true"
          @click="isCollapse = false"
        ></i>
        <el-button type="primary" plain @click="loginOut">登出</el-button>
      </div>
      <div class="rightBottom">
        <router-view></router-view>
      </div>
    </div>
  </div>
</template>

<script>
import myitem from "./components/myitem.vue";
export default {
  name: "Home",
  components: {
    myitem,
  },
  data() {
    return {
      isCollapse: false,
      activeIndex: this.$route.path,
      // 然后再通过权限管理页面，去添加或修改这个树结构，这样的话，前端就会呈现出来了
      menuArr: [
        {
          name: "前端三大框架",
          path: "前端三大框架",
          icon: "el-icon-s-home",
          children: [
            {
              name: "vue页面",
              path: "/vue",
              icon: "el-icon-star-off",
              children: [],
            },
            {
              name: "react页面",
              path: "/react",
              icon: "el-icon-star-off",
              children: [],
            },
            {
              name: "angular页面",
              path: "/angular",
              icon: "el-icon-star-off",
              children: [],
            },
          ],
        },
        {
          name: "后端两大框架",
          path: "后端两大框架",
          icon: "el-icon-s-cooperation",
          children: [
            {
              name: "Spring Boot页面",
              path: "/springBoot",
              icon: "el-icon-star-off",
              children: [],
            },
            {
              name: "Spring页面",
              path: "Spring页面", // 有children，name和path就保持一致；没有的话，path的值就是路由表中用到的，不保持一致也行，因为不会用到
              icon: "el-icon-star-off",
              children: [
                {
                  name: "MySql页面",
                  path: "/mysql",
                  icon: "el-icon-star-off",
                  children: [],
                },
                {
                  name: "Redis页面",
                  path: "/redis",
                  icon: "el-icon-star-off",
                  children: [],
                },
              ],
            },
            {
              name: "Mybatis页面",
              path: "/mybatis",
              icon: "el-icon-star-off",
              children: [],
            },
          ],
        },
        {
          name: "onlyOne",
          path: "/onlyOne",
          icon: "el-icon-star-off",
          children: [],
        },
      ],
    };
  },
  mounted() {},
  methods: {
    menuSelect(index) {
      this.activeIndex = index;
    },
    loginOut() {
      this.$router.push({
        path: "/login",
      });
      sessionStorage.removeItem("token");
    },
  },
};
</script>

<style lang="less" scoped>
.homeBox {
  width: 100%;
  height: 100%;
  display: flex;
  .left {
    // 因为要折叠，所以看度不写死
    max-width: 216px;
    height: 100%;
    .leftNav {
      max-width: 216px;
      height: 100%;
      .elMenu {
        width: 100%;
        height: 100%;
      }
      // 菜单选中高亮样式
      /deep/ .el-menu-item.is-active {
        background-color: #478ce9 !important;
        font-weight: bold;
      }
    }
  }
  .right {
    // 通过弹性盒左右自适应布局
    flex: 1;
    height: 100%;
    .rightTop {
      width: 100%;
      height: 60px;
      background-color: rgb(161, 238, 208);
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 0 20px;
      i {
        font-size: 36px;
        cursor: pointer;
      }
    }
    .rightBottom {
      width: 100%;
      height: calc(100% - 60px);
    }
  }
}

/*通过css隐藏文字，当菜单被折叠的时候，会多一个el-menu--collapse的类，所以
通过把这个类下的对应层级里面的标题文字和对应小箭头隐藏起来*/
/deep/ .el-menu--collapse .el-submenu .el-submenu__title span {
  display: none;
}
/deep/ .el-menu--collapse .el-submenu .el-submenu__title .el-submenu__icon-arrow {
  display: none;
}
</style>
